import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
// import ElementUI from "element-ui";
// import "element-ui/lib/theme-chalk/index.css";
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
import axios from "axios";
import Print from './plugins/print/print';
import moment from 'moment';
import websocket from '@/store/websocket';

Vue.use(Print);
Vue.use(websocket);

// axios.defaults.baseURL = "/api/";
// axios.defaults.baseURL = "http://127.0.0.1:8911/api/";
Vue.config.productionTip = false;
// Vue.use(ElementUI);
Vue.use(Antd)
moment.locale('zh-cn');
// 引入lodash
import _ from 'lodash';

Vue.prototype._ = _

Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(
            RegExp.$1,
            (this.getFullYear() + "").substr(4 - RegExp.$1.length)
        );
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(
                RegExp.$1,
                RegExp.$1.length == 1 ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};

Vue.prototype.downloadfile = function (res) {
    this.batchExportLoading = false
    var blob = new Blob([res.data], {type: 'application/octet-stream;charset=UTF-8'})
    var contentDisposition = res.headers['content-disposition']

    let date = new Date()
    let y = date.getFullYear()
    let MM = date.getMonth() + 1
    MM = MM < 10 ? "0" + MM : MM
    let d = date.getDate()
    d = d < 10 ? "0" + d : d

    var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
    var result = patt.exec(contentDisposition)
    var filename = y + '' + MM + '' + '' + d + this.$route.query.routerName + '.xls';
    var downloadElement = document.createElement('a')
    var href = window.URL.createObjectURL(blob) // 创建下载的链接
    var reg = /^["](.*)["]$/g
    downloadElement.style.display = 'none'
    downloadElement.href = href
    downloadElement.download = decodeURI(filename.replace(reg, '$1')) // 下载后文件名
    document.body.appendChild(downloadElement)
    downloadElement.click() // 点击下载
    document.body.removeChild(downloadElement) // 下载完成移除元素
    window.URL.revokeObjectURL(href)
}


new Vue({
    router,
    store,
    render: h => h(App)
}).$mount("#app");
